/*****************************************************************************
 * plum_fsm_service_test.c
 *
 * Copyright (C) 2020 Jeasonvor 1101627719@qq.com
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 ****************************************************************************/

/*****************************************************************************
 * Included Files
 ****************************************************************************/
#include "plum_api.h"
/*****************************************************************************
 * Trace Definitions
 ****************************************************************************/
#define LOG_RUN_LEVEL LOG_LEVEL_DEBUG
#define LOG_MODULE    "fsm.srv.test"
#include "thirdparty/log/log.h"
/*****************************************************************************
 * Pre-processor Definitions
 ****************************************************************************/

/*****************************************************************************
 * Private Types
 ****************************************************************************/

/*****************************************************************************
 * Private Function Prototypes
 ****************************************************************************/

/*****************************************************************************
 * Private Data
 ****************************************************************************/

/*****************************************************************************
 * Public Data
 ****************************************************************************/

/*****************************************************************************
 * Private Functions
 ****************************************************************************/

PLUM_PRIVATE
plum_s32 test_service_select(plum_void)
{
    plum_s32 rc = PLUM_ECODE_OK;

    LOG_I("==== device service_list ====");
    LOG_I("device naem : service_test");
    LOG_I(" serivce id[0x0800] ,print log,param null");
    LOG_I(" service id[0x0801] ,get id,param null");

    return (rc);
}

PLUM_PRIVATE
plum_s32 test_service_handler(plum_u32 srv_id, plum_s8 *argv[])
{
    plum_s32 rc = PLUM_ECODE_OK;

    LOG_I("service handle get id : 0x%32X", srv_id);

    switch (srv_id) {
        case 0x0800:
            /* to do  */
            {
            }
            break;

        case 0x0801:
            /* to do  */
            {
            }
            break;

        default:
            break;
    }

    PLUM_UNUSED(argv);

    return (rc);
}

PLUM_CAL_FSM_SERVICE_REGISTER("service_test", test_service_select,
                              test_service_handler);

PLUM_CAL_FSM_ATTR_REGISTER(1, 3);
/*****************************************************************************
 * Public Functions
 ****************************************************************************/

int main(void)
{
    plum_s32 rc = 0;

    rc = plum_cal_cli_init(getchar);
    if (rc) {
        LOG_E("init cli err,rc:%d", rc);
    }

    while (1) {
        plum_kal_thread_delay(10000);
    }
}

/*****************************************************************************
 * Cli Functions
 ****************************************************************************/

PLUM_PRIVATE
plum_void test_fsm_service_cli_call(plum_u32 argc, plum_s8 *argv[])
{
    plum_u32 loop = 0;

    for (loop = 0; loop < argc; loop++) {
        LOG_I("argv[%d] : %s", loop, argv[loop]);
    }

    plum_s8 dev_name[32] = {0};
    snprintf((char *)dev_name, sizeof(dev_name), "%s", argv[0]);
    plum_u32 srv_id = strtoul((char *)argv[1], NULL, 16);

    LOG_I("call %s service : 0x%32X", dev_name, srv_id);
    plum_cal_fsm_srv_call(dev_name, srv_id, plum_null);
}
PLUM_CAL_CLI_EXPORT("srv_call", "call system service",
                    test_fsm_service_cli_call);

PLUM_PRIVATE
plum_void test_fsm_service_cli_select(plum_u32 argc, plum_s8 *argv[])
{
    plum_u32 loop = 0;

    for (loop = 0; loop < argc; loop++) {
        LOG_I("argv[%d] : %s", loop, argv[loop]);
    }

    plum_s8 dev_name[32] = {0};
    snprintf((char *)dev_name, sizeof(dev_name), "%s", argv[0]);

    LOG_I("select %s services", dev_name);
    plum_cal_fsm_srv_info(dev_name);
}
PLUM_CAL_CLI_EXPORT("srv_get", "select device services",
                    test_fsm_service_cli_select);

/****************************************************************************/
/*                                                                          */
/*  End of file.                                                            */
/*                                                                          */
/****************************************************************************/
